/**
 * 验证是否为空
 * @param argument 传入验证参数
 * @param str 错误提示语句
 * @param num 1代表用户名，2代表密码
 */
function valid(argument,str,num){
    if(argument === ''){
        if(num == 1){
            $('.admin_input_style').data({'error':1});
            $(".error-username").show();
            $(".error-username").html(str);
            $('#user').css({'outline-color':'#fa6060','border-color':'#fa6060'});
        }
        if(num == 2){
            $('.admin_input_style').data({'error':1});
            $(".error-pwd").show();
            $(".error-pwd").html(str);
            $('#pwd').css({'outline-color':'#fa6060','border-color':'#fa6060'});
        }
    }else{
        if(num == 1){
            $('.admin_input_style').data({'error':0});
            $(".error-username").hide();
            $('#user').css({'outline-color':'#99bbf2','border-color':'#eee'});
        }
        if(num == 2) {
            $('.admin_input_style').data({'error':0});
            $(".error-pwd").hide();
            $('#pwd').css({'outline-color':'#99bbf2','border-color':'#eee'});
        }
    }
}

function login(){
    var name = $('#user').val();
    var password = $('#pwd').val();
    valid(name,'* 用户名不能为空！',1);
    valid(password,'* 密码不能为空！',2);
    var err = 0;
    $('.admin_input_style').each(function () {
        err +=$(this).data('error');
    });
    if(err<1){
        $.ajax({
            url : 'http://'+window.location.host+'/baibu/admin/Login/login',
            dataType : 'json',
            type : "post",
            data : {username : name, password : password},
            success : function (data) {
                if(data.status == 1){
                    location.href = 'http://'+window.location.host+'/baibu/admin/Index/index';
                }else{
                    alert(data.msg);
                    $('#user,#pwd').val('');
                }
            }
        });
    }
}

function site(){
    location.href = "index";
}

function getMneu(mark,menu){
    var html = '';
    $.each(menu,function (i,item) {
        if(item.menu_desc == mark){
            html += '<li class="active"><a href="'+item.menu_url+'">'+item.menu_name+'</a></li>';
        }else{
            html += '<li><a href="'+item.menu_url+'">'+item.menu_name+'</a></li>';
        }
    });
    return html;
}